// File:       poscmd07.c++
// Version:    1.00
// Author:     (c) Miles Sabin, 1997
// Purpose:    seekoff command

// Change log:
//  29/03/97   v. 1.00

#include "poscmds.h"

#include "ostream.h"
#include "streambuf.h"


// Implementation of OStreamSeekoffCommand

OStreamSeekoffCommand::OStreamSeekoffCommand(basic_ostream_char& os, int off, ios::seekdir way, ios::openmode which)
  : off_(off),
    way_(way),
    which_(which)
  { execute_template(os); }

OStreamSeekoffCommand::~OStreamSeekoffCommand()
  {}

ios::iostate OStreamSeekoffCommand::execute(basic_ostream_char& os)
  {
    result_ = os.rdbuf()->pubseekoff(off_, way_, which_);
    return ios::goodbit;
  }


// Implementation of basic_ostream_char

int basic_ostream_char::tellp()
  {
    if(fail())
      return -1;

    OStreamSeekoffCommand cmd(*this, 0, cur, out);
    return cmd.as_int();
  }

basic_ostream_char& basic_ostream_char::seekp(int off, seekdir dir)
  {
    if(!fail())
    {
      OStreamSeekoffCommand cmd(*this, off, dir);
    }
    return *this;
  }
